/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUInemeanshop;

import components.NButton;
import components.NKeyListener;
import components.NLabel;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
import nemeanshop.NemeanShop;

/**
 *
 * @author havardaxelsen
 */
public class GUIMenu extends JPanel{
    
    private ImageIcon img       = new ImageIcon("src/GUInemeanshop/img/sbtn1.png");
    private ImageIcon logo      = new ImageIcon("src/GUInemeanshop/img/logo_small.png");
    private ImageIcon statimg   = new ImageIcon("src/GUInemeanshop/img/small/Statsmall.png");
    private ImageIcon kurvimg   = new ImageIcon("src/GUInemeanshop/img/small/kurvsmall.png");
    private ImageIcon prodlogo  = new ImageIcon("src/GUInemeanshop/img/small/prodlistsmall.png");
    private ImageIcon prodnotify  = new ImageIcon("src/GUInemeanshop/img/small/prodnotify.png");
    private ImageIcon selgeimg  = new ImageIcon("src/GUInemeanshop/img/small/selgeimg.png"); 
    private ImageIcon instimg   = new ImageIcon("src/GUInemeanshop/img/small/instillingersmall.png");
    private ImageIcon logutimg  = new ImageIcon("src/GUInemeanshop/img/small/logoutsmall.png");
    
    private ImageIcon statimgmo   = new ImageIcon("src/GUInemeanshop/img/small/Statsmall_mo.png");
    private ImageIcon kurvimgmo   = new ImageIcon("src/GUInemeanshop/img/small/kurvsmall_mo.png");
    private ImageIcon prodlogomo  = new ImageIcon("src/GUInemeanshop/img/small/prodlistsmall_mo.png");
    private ImageIcon selgeimgmo  = new ImageIcon("src/GUInemeanshop/img/small/selgeimg_mo.png"); 
    private ImageIcon instimgmo   = new ImageIcon("src/GUInemeanshop/img/small/instillingersmall_mo.png");
    private ImageIcon logutimgmo  = new ImageIcon("src/GUInemeanshop/img/small/logoutsmall_mo.png");
    
    private ImageIcon prodnotifymo  = new ImageIcon("src/GUInemeanshop/img/small/prodnotify_mo.png");
    
    private NKeyListener k      = new NKeyListener();
    private NButton loggut      = new NButton("Logg ut", k);
    private NButton pliste      = new NButton("Produktliste"); 
    private NButton kurv        = new NButton("Kurv");
    private NButton settings    = new NButton("Innstillinger");
    private NButton selgere     = new NButton("Selgere");
    private NButton stats       = new NButton("Stats");
    private NLabel innlogget    = new NLabel("Innlogget: ");
    private NButton logolbl;
    private MenuLeft ml         = new MenuLeft();
    private MenuRight mr        = new MenuRight();
    
    private GUIContent gc;
    private NemeanShop ns;
    private Dimension d     = new Dimension(1200,100);
    
    
    public GUIMenu(final GUIContent gc, final NemeanShop ns){
        this.gc = gc;
        this.ns = ns;
        this.setLayout(new GridLayout(1,2));
        this.setPreferredSize(d);
        pliste.setBorder(null);
        
        logolbl     = new NButton("Home",logo, logo, gc, GUIContent.HP);
        pliste      = new NButton("Produktliste", prodlogo,prodlogomo,  gc, GUIContent.GPL);
        kurv        = new NButton("Handlekurv", kurvimg, kurvimgmo, gc, GUIContent.BP);
        settings    = new NButton("Instillinger",instimg , instimgmo, gc, GUIContent.SETTINGS);
        selgere     = new NButton("Selgere", selgeimg, selgeimgmo, gc, GUIContent.GC);
        stats       = new NButton("Statistikk", statimg, statimgmo, gc, GUIContent.STATS);
        loggut      = new NButton("Logg ut",logutimg, logutimgmo, gc, GUIContent.LOG, ns);
        
        ml.add(logolbl);
        ml.add(pliste);
        ml.add(kurv);
        ml.add(settings);
        ml.add(selgere);
        ml.add(stats);
        mr.add(innlogget);
        mr.add(loggut);
        
        this.add(ml);
        this.add(mr);
        this.setBackground(new Color(238,233,233));
        this.setBorder(BorderFactory.createLineBorder(Color.black, 1));
    }
    
    public void setNotification(boolean b)
    {
        if (b)
        {
            pliste.setIcon(prodnotify);
            pliste.setRolloverIcon(prodnotifymo);
            pliste.setBorder(null);
        }
        else
        {
            pliste.setIcon(prodlogo);
            pliste.setRolloverIcon(prodlogomo);
            pliste.setBorder(null);
        }
    }
    
    
    
    
    public void setCashier(String s){
        innlogget.setText("Innlogget: " +s);
    }     
            
    private class Knappelytter implements ActionListener{

        @Override
        public void actionPerformed(ActionEvent ae) {
            NButton b = (NButton)ae.getSource();
            System.out.println("!!!!");
            if(b.getText().equals("Logg ut")){
                System.out.println("Logg ut");
                gc.showCard(GUIContent.LOG);
                ns.removeCashier();
            }
            
            
        }
    
}
}

class MenuLeft extends JPanel{
    
    public MenuLeft(){
        this.setLayout(new GridLayout(1,6));
        this.setBorder(BorderFactory.createEmptyBorder(5,20,5,20));
        this.setBackground(null);
    }
}

    
    class MenuRight extends JPanel{
    
    public MenuRight(){
        this.setLayout(new GridLayout(1,2));
        this.setBorder(BorderFactory.createEmptyBorder(5,20,5,20));
        this.setBackground(null);
    }

}
